package org.jwos.plugin.file.domain;

import java.util.HashMap;
import java.util.Map;

public class FolderType {
	
	public static final long MaxFileSize = 102400000;       //100M
	public static final long MaxStorageSize = 1024000000;   //1G
	public static final long MaxBandwidthSize = 1024000000; //1G 
	
	public static final int FileViewThumbs  = 0;
	public static final int FileViewTiles   = 1;
	public static final int FileViewIcons   = 2;
	public static final int FileViewDetails = 3;
	
	public static final String[] FileViewNames = new String[] {
		"thumbs","tiles","icons","details"
	};
		
	public static final int None = 0;
	public static final int RootFolder = 1;
	public static final int RecycleBin = 2;
	public static final int PhotoGallery = 3;
	public static final int FileFolder = 4;
	public static final int PhotoAlbum = 5;
	public static final int MyNetwork = 6;
	public static final int MyNetworkUser = 7;
	public static final int SharedDocuments = 8;
	public static final int SharedAlbums = 9;
	public static final int SharedFolder = 10;
	public static final int SharedAlbum = 11;
	public static final int PublishedItems = 12;
	public static final int PublishedFiles = 13;
	public static final int PublishedFolders = 14;
	public static final int SearchResults = 15;
	public static final int TagsFolder = 16;
	public static final int TempFolder = 17;
	
	public static final String[] FolderNames = new String[] {
		"None",
		"My Folders",
		"Recycle Bin",
		"My Photo Gallery",
		"FileFolder",
		"PhotoAlbum",
		"My Network",
		"MyNetworkUser",
		"Shared",
		"SharedAlbums",
		"SharedFolder",
		"SharedAlbum",
		"Published",
		"Files",
		"Folders",
		"Search Results",
		"Tags",
		"Temp"
	};
	
	public static final int Status_None = 0;
	public static final int Status_Shared = 1;
	public static final int Status_Published = 2;
	public static final int Status_SharedPublished = 3;
	
	public static final int ThumbnailWidth  = 80;
	public static final int ThumbnailHeight = 60;
	
	public static Map FileIconMap = new HashMap();
	
	public static Map ThumbnailTypeMap = new HashMap();
	
	static {
		FileIconMap.put("3gp", "3gp");
		FileIconMap.put("avi", "avi");
		FileIconMap.put("bmp", "bmp");
		FileIconMap.put("chm", "chm");
		FileIconMap.put("dll", "dll");
		FileIconMap.put("doc", "doc");
		FileIconMap.put("exe", "exe");
		FileIconMap.put("gif", "gif");
		FileIconMap.put("htm", "htm");
		FileIconMap.put("html", "htm");
		FileIconMap.put("jpg", "jpg");
		FileIconMap.put("jpeg", "jpg");
		FileIconMap.put("log", "txt");
		FileIconMap.put("mdb", "mdb");
		FileIconMap.put("mov", "mov");
		FileIconMap.put("mp3", "mp3");
		FileIconMap.put("mpg", "mpg");
		FileIconMap.put("pdf", "pdf");
		FileIconMap.put("png", "jpg");
		FileIconMap.put("pps", "pps");
		FileIconMap.put("ppt", "ppt");
		FileIconMap.put("rar", "rar");
		FileIconMap.put("rtf", "rtf");
		FileIconMap.put("txt", "txt");
		FileIconMap.put("wav", "wav");
		FileIconMap.put("wma", "wma");
		FileIconMap.put("xls", "xls");
		FileIconMap.put("xml", "xml");
		FileIconMap.put("zip", "zip");
		
		ThumbnailTypeMap.put("bmp", "bmp");
		ThumbnailTypeMap.put("gif", "gif");		
		ThumbnailTypeMap.put("jpg", "jpg");
		ThumbnailTypeMap.put("jpeg", "jpg");		
		ThumbnailTypeMap.put("png", "png");
	}
	
	public static boolean isNeedThumbnail(String fileName) {
		boolean result = false;
		
		if(fileName!=null && fileName.lastIndexOf(".")>0) {
			int index = fileName.lastIndexOf(".");
			if(fileName.length()>index+1) {
				String ext = fileName.substring(index+1, fileName.length()).toLowerCase();
				if(ThumbnailTypeMap.containsKey(ext)){
					result = true;
				}
			}
		}
		
		return result;
	}
	
	public static String getIconClassByFolderType(int folderType,boolean shared) {
		
		String type = "folder";
		
		switch(folderType) {
			case FolderType.RootFolder:
				type = "root"; 
				break;
			case FolderType.RecycleBin:
				type = "recyclebin"; 
				break;
			case FolderType.PhotoGallery:
				type = "gallery"; 
				break;
			case FolderType.MyNetwork:
				type = "network"; 
				break;
			case FolderType.MyNetworkUser:
				type = "network-user";
				break;				
			case FolderType.FileFolder:
			case FolderType.SharedFolder:
				if(shared) {
					type = "folder-shared";
				}				 
				break;			
			case FolderType.PublishedItems:
				type = "published"; 
				break;
			case FolderType.PublishedFiles:
				type = "published-files"; 
				break;
			case FolderType.PublishedFolders:
				type = "published-folders"; 
				break;
		}
		
		return "db-ft-"+type+"-small";
	}
	
	public static String getIconByFileExt(String ext) {
		String icon = "unknown";
		
		if(ext!=null && ext.length()>0 && FileIconMap.containsKey(ext)) {
			icon = (String)FileIconMap.get(ext);
		} 
		
		return icon;
	}
	
	public static boolean getAllowDragByFolderType(int folderType) {
		boolean allowDrag = false;
		
		switch(folderType) {
			case FolderType.FileFolder:
				allowDrag = true;
				break;
		}
		
		return allowDrag;
	}
	
	public static boolean getAllowDropByFolderType(int folderType) {
		boolean allowDrag = false;
		
		switch(folderType) {
			case FolderType.FileFolder:
				allowDrag = true;
				break;
		}
		
		return allowDrag;
	}
	
	public static boolean isTopFolder(int folderType) {
		
		boolean isTop = false;
		
		switch(folderType) {
			case FolderType.RootFolder:
 			case FolderType.RecycleBin:
			case FolderType.PhotoGallery:
			case FolderType.MyNetwork:
			case FolderType.PublishedItems:
				isTop = true;
				break;
		}
		
		return isTop;
	}
	
	public static String formatSize(long size) {
		if (size == 0) {
            return "";
        }
        if (size<1024) {
	        return Math.floor(size*100)/100+" bytes";
        }
        if (size<1048576) {
	        return Math.floor((size/1024)*100)/100+" KB";
        }
        if (size<1073741824) {
	        return Math.floor((size/1048576)*100)/100+" MB";
        }
        return Math.floor((size/1073741824)*100)/100+" GB";
	}

}
